home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Include / GuiList.au3 < prev    next >
Encoding:
Text File  |  2007-09-08  |  48.1 KB  |  1,052 lines

  1. #include-once
  2. #include <ListBoxConstants.au3>
  3. #include <Misc.au3>
  4. #include <Memory.au3>
  5.  
  6. ; ------------------------------------------------------------------------------
  7. ;
  8. ; AutoIt Version: 3.2.3++
  9. ; Language:       English
  10. ; Description:    Functions that assist with Listbox.
  11. ;
  12. ; ------------------------------------------------------------------------------
  13.  
  14. ; ------------------------------------------------------------------------------
  15. ; These functions use some code developed by Paul Campbell (PaulIA) for the Auto3Lib project
  16. ; particularly the _Mem* function calls which can be found in Memory.au3
  17. ; ------------------------------------------------------------------------------
  18.  
  19. ; function list
  20. ;===============================================================================
  21. ; _GUICtrlListAddDir
  22. ; _GUICtrlListAddItem
  23. ; _GUICtrlListClear
  24. ; _GUICtrlListCount
  25. ; _GUICtrlListDeleteItem
  26. ; _GUICtrlListFindString
  27. ; _GUICtrlListGetAnchorIndex
  28. ; _GUICtrlListGetCaretIndex
  29. ; _GUICtrlListGetHorizontalExtent
  30. ; _GUICtrlListGetInfo
  31. ; _GUICtrlListGetLocale
  32. ; _GUICtrlListGetSelCount
  33. ; _GUICtrlListGetSelItems
  34. ; _GUICtrlListGetSelItemsText
  35. ; _GUICtrlListGetSelState
  36. ; _GUICtrlListGetText
  37. ; _GUICtrlListGetTextLen
  38. ; _GUICtrlListGetTopIndex
  39. ; _GUICtrlListInsertItem
  40. ; _GUICtrlListReplaceString
  41. ; _GUICtrlListSelectedIndex
  42. ; _GUICtrlListSelectString
  43. ; _GUICtrlListSelItemRange
  44. ; _GUICtrlListSelItemRangeEx
  45. ; _GUICtrlListSetAnchorIndex
  46. ; _GUICtrlListSetCaretIndex
  47. ; _GUICtrlListSetHorizontalExtent
  48. ; _GUICtrlListSetLocale
  49. ; _GUICtrlListSetSel
  50. ; _GUICtrlListSetTopIndex
  51. ; _GUICtrlListSort
  52. ; _GUICtrlListSwapString
  53. ;
  54. ; ************** TODO ******************
  55. ; _GUICtrlListAddFile
  56. ;===============================================================================
  57.  
  58. ;===============================================================================
  59. ;
  60. ; Description:            _GUICtrlListAddDir
  61. ; Parameter(s):        $h_listbox - controlID
  62. ;                            $s_Attributes - Comma-delimited string
  63. ;                            $s_file - Optional for "Drives" only: what to get i.e *.*
  64. ; Requirement:            None
  65. ; Return Value(s):    zero-based index of the last name added to the list
  66. ;                            If an error occurs, the return value is $LB_ERR.
  67. ;                            If there is insufficient space to store the new strings, the return value is $LB_ERRSPACE
  68. ; User CallTip:        _GUICtrlListAddDir($h_listbox, $s_Attributes[, $s_file=""]) Add names to the list displayed by the list box (required: <GuiList.au3>)
  69. ; Author(s):            Gary Frost (custompcs at charter dot net)
  70. ;                    CyberSlug
  71. ; Note(s):                $s_Attributes is an comma-delimited string
  72. ;                             valid values are any of the following:
  73. ;                                 A,D,H,RO,RW,S,E,Drives,NB
  74. ;                            A = ARCHIVE
  75. ;                                Includes archived files.
  76. ;                            D = DIRECTORY
  77. ;                                Includes subdirectories. Subdirectory names are enclosed in square brackets ([ ]).
  78. ;                            H = HIDDEN
  79. ;                                Includes hidden files.
  80. ;                            RO = READONLY
  81. ;                                Includes read-only files.
  82. ;                            RW = READWRITE
  83. ;                                Includes read-write files with no additional attributes. This is the default setting.
  84. ;                            S = SYSTEM
  85. ;                                Includes system files.
  86. ;                            E = EXCLUSIVE
  87. ;                                Includes only files with the specified attributes. By default, read-write files are listed even if READWRITE is not specified.
  88. ;                            DRIVES
  89. ;                                All mapped drives are added to the list. Drives are listed in the form [-x-], where x is the drive letter.
  90. ;                            NB = No Brackets
  91. ;                               Drives are liste in the form x:, where x is the drive letter (used with Drives attribute)
  92. ;
  93. ;===============================================================================
  94. Func _GUICtrlListAddDir($h_listbox, $s_Attributes, $s_file = "")
  95.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  96.     Local $i, $v_Attributes = "", $i_drives = 0, $no_brackets = 0, $v_ret
  97.     Local $a_Attributes = StringSplit($s_Attributes, ",")
  98.     For $i = 1 To $a_Attributes[0]
  99.         Select
  100.             Case StringUpper($a_Attributes[$i]) = "A"
  101.                 If (StringLen($v_Attributes) > 0) Then
  102.                     $v_Attributes = $v_Attributes + $DDL_ARCHIVE
  103.                 Else
  104.                     $v_Attributes = $DDL_ARCHIVE
  105.                 EndIf
  106.             Case StringUpper($a_Attributes[$i]) = "D"
  107.                 If (StringLen($v_Attributes) > 0) Then
  108.                     $v_Attributes = $v_Attributes + $DDL_DIRECTORY
  109.                 Else
  110.                     $v_Attributes = $DDL_DIRECTORY
  111.                 EndIf
  112.             Case StringUpper($a_Attributes[$i]) = "H"
  113.                 If (StringLen($v_Attributes) > 0) Then
  114.                     $v_Attributes = $v_Attributes + $DDL_HIDDEN
  115.                 Else
  116.                     $v_Attributes = $DDL_HIDDEN
  117.                 EndIf
  118.             Case StringUpper($a_Attributes[$i]) = "RO"
  119.                 If (StringLen($v_Attributes) > 0) Then
  120.                     $v_Attributes = $v_Attributes + $DDL_READONLY
  121.                 Else
  122.                     $v_Attributes = $DDL_READONLY
  123.                 EndIf
  124.             Case StringUpper($a_Attributes[$i]) = "RW"
  125.                 If (StringLen($v_Attributes) > 0) Then
  126.                     $v_Attributes = $v_Attributes + $DDL_READWRITE
  127.                 Else
  128.                     $v_Attributes = $DDL_READWRITE
  129.                 EndIf
  130.             Case StringUpper($a_Attributes[$i]) = "S"
  131.                 If (StringLen($v_Attributes) > 0) Then
  132.                     $v_Attributes = $v_Attributes + $DDL_SYSTEM
  133.                 Else
  134.                     $v_Attributes = $DDL_SYSTEM
  135.                 EndIf
  136.             Case StringUpper($a_Attributes[$i]) = "DRIVES"
  137.                 $i_drives = 1
  138.                 $s_file = ""
  139.                 If (StringLen($v_Attributes) > 0) Then
  140.                     $v_Attributes = $v_Attributes + $DDL_DRIVES
  141.                 Else
  142.                     $v_Attributes = $DDL_DRIVES
  143.                 EndIf
  144.             Case StringUpper($a_Attributes[$i]) = "E"
  145.                 If (StringLen($v_Attributes) > 0) Then
  146.                     $v_Attributes = $v_Attributes + $DDL_EXCLUSIVE
  147.                 Else
  148.                     $v_Attributes = $DDL_EXCLUSIVE
  149.                 EndIf
  150.  
  151.             Case StringUpper($a_Attributes[$i]) = "NB"
  152.                 If (StringLen($v_Attributes) > 0) And StringInStr($s_Attributes, "DRIVES") Then
  153.                     $no_brackets = 1
  154.                 Else
  155.                     $no_brackets = 0
  156.                 EndIf
  157.             Case Else
  158.                 ; invalid attribute
  159.                 Return $LB_ERRATTRIBUTE
  160.         EndSelect
  161.     Next
  162.     If (Not $i_drives And StringLen($s_file) == 0) Then
  163.         Return $LB_ERRREQUIRED
  164.     EndIf
  165.     If $i_drives And $no_brackets Then
  166.         Local $s_text
  167.         Local $gui_no_brackets = GUICreate("no brackets")
  168.         Local $list_no_brackets = GUICtrlCreateList("", 240, 40, 120, 120)
  169.         $v_ret = GUICtrlSendMsg($list_no_brackets, $LB_DIR, $v_Attributes, $s_file)
  170.         For $i = 0 To _GUICtrlListCount($list_no_brackets) - 1
  171.             $s_text = _GUICtrlListGetText($list_no_brackets, $i)
  172.             $s_text = StringReplace(StringReplace(StringReplace($s_text, "[", ""), "]", ":"), "-", "")
  173.             _GUICtrlListInsertItem($h_listbox, $s_text)
  174.         Next
  175.         GUIDelete($gui_no_brackets)
  176.         Return $v_ret
  177.     Else
  178.         If IsHWnd($h_listbox) Then
  179.             Return _SendMessage($h_listbox, $LB_DIR, $v_Attributes, $s_file, 0, "int", "str")
  180.         Else
  181.             Return GUICtrlSendMsg($h_listbox, $LB_DIR, $v_Attributes, $s_file)
  182.         EndIf
  183.     EndIf
  184. EndFunc   ;==>_GUICtrlListAddDir
  185.  
  186. ;===============================================================================
  187. ;
  188. ; Description:            _GUICtrlListAddItem
  189. ; Parameter(s):        $h_listbox - controlID
  190. ;                            $s_text - string to add
  191. ; Requirement:            None
  192. ; Return Value(s):    The return value is the zero-based index of the string in
  193. ;                            the list box. If an error occurs, the return value is $LB_ERR.
  194. ;                            If there is insufficient space to store the new string,
  195. ;                            the return value is $LB_ERRSPACE.
  196. ; User CallTip:        _GUICtrlListAddItem($h_listbox, $s_text) Add an item to the List (required: <GuiList.au3>)
  197. ; Author(s):            Gary Frost (custompcs at charter dot net)
  198. ; Note(s):                If the list box does not have the LBS_SORT style, the string is added to the
  199. ;                             end of the list. Otherwise, the string is inserted into the list and the list
  200. ;                             is sorted.
  201. ;
  202. ;===============================================================================
  203. Func _GUICtrlListAddItem($h_listbox, $s_text)
  204.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  205.     If IsHWnd($h_listbox) Then
  206.         Return _SendMessage($h_listbox, $LB_ADDSTRING, 0, $s_text, 0, "int", "str")
  207.     Else
  208.         Return GUICtrlSendMsg($h_listbox, $LB_ADDSTRING, 0, String($s_text))
  209.     EndIf
  210. EndFunc   ;==>_GUICtrlListAddItem
  211.  
  212. ;===============================================================================
  213. ;
  214. ; Description:            _GUICtrlListClear
  215. ; Parameter(s):        $h_listbox - controlID
  216. ; Requirement:            None
  217. ; Return Value(s):    None
  218. ; User CallTip:        _GUICtrlListClear($h_listbox) remove all items from the list box (required: <GuiList.au3>)
  219. ; Author(s):            Gary Frost (custompcs at charter dot net)
  220. ; Note(s):                None
  221. ;
  222. ;===============================================================================
  223. Func _GUICtrlListClear($h_listbox)
  224.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, 0)
  225.     If IsHWnd($h_listbox) Then
  226.         _SendMessage($h_listbox, $LB_RESETCONTENT)
  227.     Else
  228.         GUICtrlSendMsg($h_listbox, $LB_RESETCONTENT, 0, 0)
  229.     EndIf
  230. EndFunc   ;==>_GUICtrlListClear
  231.  
  232. ;===============================================================================
  233. ;
  234. ; Description:            _GUICtrlListCount
  235. ; Parameter(s):        $h_listbox - controlID
  236. ; Requirement:            None
  237. ; Return Value(s):    The return value is the number of items in the list box
  238. ;                            or $LB_ERR if an error occurs
  239. ; User CallTip:        _GUICtrlListCount($h_listbox) return the number of items in the list box (required: <GuiList.au3>)
  240. ; Author(s):            Gary Frost (custompcs at charter dot net)
  241. ; Note(s):                None
  242. ;
  243. ;===============================================================================
  244. Func _GUICtrlListCount($h_listbox)
  245.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  246.     If IsHWnd($h_listbox) Then
  247.         Return _SendMessage($h_listbox, $LB_GETCOUNT)
  248.     Else
  249.         Return GUICtrlSendMsg($h_listbox, $LB_GETCOUNT, 0, 0)
  250.     EndIf
  251. EndFunc   ;==>_GUICtrlListCount
  252.  
  253. ;===============================================================================
  254. ;
  255. ; Description:            _GUICtrlListDeleteItem
  256. ; Parameter(s):        $h_listbox - controlID
  257. ;                            $i_index - index of item to delete
  258. ; Requirement:            None
  259. ; Return Value(s):    The return value is a count of the strings remaining in the list.
  260. ;                            The return value is $LB_ERR if the $i_index parameter specifies an
  261. ;                            index greater than the number of items in the list.
  262. ; User CallTip:        _GUICtrlListDeleteItem($h_listbox, $i_index) Delete an Item from the List (required: <GuiList.au3>)
  263. ; Author(s):            Gary Frost (custompcs at charter dot net)
  264. ; Note(s):                None
  265. ;
  266. ;===============================================================================
  267. Func _GUICtrlListDeleteItem($h_listbox, $i_index)
  268.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  269.     If IsHWnd($h_listbox) Then
  270.         Return _SendMessage($h_listbox, $LB_DELETESTRING, $i_index)
  271.     Else
  272.         Return GUICtrlSendMsg($h_listbox, $LB_DELETESTRING, $i_index, 0)
  273.     EndIf
  274. EndFunc   ;==>_GUICtrlListDeleteItem
  275.  
  276. ;===============================================================================
  277. ;
  278. ; Description:            _GUICtrlListFindString
  279. ; Parameter(s):        $h_listbox - controlID
  280. ;                            $s_search - string to search for
  281. ;                            $i_exact - exact match or not
  282. ; Requirement:            None
  283. ; Return Value(s):    The return value is the index of the matching item,
  284. ;                            or $LB_ERR if the search was unsuccessful.
  285. ; User CallTip:        _GUICtrlListFind($h_listbox, $s_search[, $i_exact=0]) return the index of matching item (required: <GuiList.au3>)
  286. ; Author(s):            Gary Frost (custompcs at charter dot net)
  287. ; Note(s):                find the first string in a list box that begins with the specified string.
  288. ;                            if exact is specified find the first list box string that exactly matches
  289. ;                    the specified string, except that the search is not case sensitive
  290. ;===============================================================================
  291. Func _GUICtrlListFindString($h_listbox, $s_search, $i_exact = 0)
  292.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  293.     If IsHWnd($h_listbox) Then
  294.         If ($i_exact) Then
  295.             Return _SendMessage($h_listbox, $LB_FINDSTRINGEXACT, -1, $s_search, 0, "int", "str")
  296.         Else
  297.             Return _SendMessage($h_listbox, $LB_FINDSTRING, -1, $s_search, 0, "int", "str")
  298.         EndIf
  299.     Else
  300.         If ($i_exact) Then
  301.             Return GUICtrlSendMsg($h_listbox, $LB_FINDSTRINGEXACT, -1, String($s_search))
  302.         Else
  303.             Return GUICtrlSendMsg($h_listbox, $LB_FINDSTRING, -1, String($s_search))
  304.         EndIf
  305.     EndIf
  306. EndFunc   ;==>_GUICtrlListFindString
  307.  
  308. ;===============================================================================
  309. ;
  310. ; Description:            _GUICtrlListGetAnchorIndex
  311. ; Parameter(s):        $h_listbox - controlID
  312. ; Requirement:            multi-select style
  313. ; Return Value(s):    The return value is the index of the anchor item.
  314. ;                            If an error occurs, the return value is $LB_ERR
  315. ; User CallTip:        _GUICtrlListGetAnchorIndex($h_listbox) Get the Anchor Idex (required: <GuiList.au3>)
  316. ; Author(s):            CyberSlug
  317. ; Note(s):                DOES NOT WORK WITH SINGLE-SELECTION LIST BOXES
  318. ;                         This might not always be the first selected item--especially
  319. ;                          if you select every other item via Ctrl+Click...
  320. ;
  321. ;===============================================================================
  322. Func _GUICtrlListGetAnchorIndex($h_listbox)
  323.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  324.     If IsHWnd($h_listbox) Then
  325.         Return _SendMessage($h_listbox, $LB_GETANCHORINDEX)
  326.     Else
  327.         Return GUICtrlSendMsg($h_listbox, $LB_GETANCHORINDEX, 0, 0)
  328.     EndIf
  329. EndFunc   ;==>_GUICtrlListGetAnchorIndex
  330.  
  331. ;===============================================================================
  332. ;
  333. ; Description:            _GUICtrlListGetCaretIndex
  334. ; Parameter(s):        $h_listbox - controlID
  335. ; Requirement:            multi-select style
  336. ; Return Value(s):    The return value is the zero-based index of the selected list box item.
  337. ;                            If nothing is selected $LB_ERR can be returned.
  338. ; User CallTip:        _GUICtrlListGetCaretIndex($h_listbox) Return index of item that has the focus rectangle (required: <GuiList.au3>)
  339. ; Author(s):            CyberSlug
  340. ; Note(s):                To determine the index of the item that has the focus rectangle in a
  341. ;                            multiple-selection list box. The item may or may not be selected
  342. ;
  343. ;===============================================================================
  344. Func _GUICtrlListGetCaretIndex($h_listbox)
  345.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  346.     If IsHWnd($h_listbox) Then
  347.         Return _SendMessage($h_listbox, $LB_GETCARETINDEX)
  348.     Else
  349.         Return GUICtrlSendMsg($h_listbox, $LB_GETCARETINDEX, 0, 0)
  350.     EndIf
  351. EndFunc   ;==>_GUICtrlListGetCaretIndex
  352.  
  353. ;===============================================================================
  354. ;
  355. ; Description:            _GUICtrlListGetHorizontalExtent
  356. ; Parameter(s):        $h_listbox - controlID
  357. ; Requirement:            None.
  358. ; Return Value(s):    The return value is the scrollable width, in pixels, of the list box.
  359. ; User CallTip:        _GUICtrlListGetHorizontalExtent($h_listbox) Retrieve from a list box the the scrollable width (required: <GuiList.au3>)
  360. ; Author(s):            Gary Frost (custompcs at charter dot net)
  361. ; Note(s):                To respond to the $LB_GETHORIZONTALEXTENT message,
  362. ;                            the list box must have been defined with the $WS_HSCROLL style.
  363. ;
  364. ;===============================================================================
  365. Func _GUICtrlListGetHorizontalExtent($h_listbox)
  366.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  367.     If IsHWnd($h_listbox) Then
  368.         Return _SendMessage($h_listbox, $LB_GETHORIZONTALEXTENT)
  369.     Else
  370.         Return GUICtrlSendMsg($h_listbox, $LB_GETHORIZONTALEXTENT, 0, 0)
  371.     EndIf
  372. EndFunc   ;==>_GUICtrlListGetHorizontalExtent
  373.  
  374. ;===============================================================================
  375. ;
  376. ; Description:            _GUICtrlListGetInfo
  377. ; Parameter(s):        $h_listbox - controlID
  378. ; Requirement:            None.
  379. ; Return Value(s):    The return value is the number of items per column.
  380. ; User CallTip:        _GUICtrlListGetInfo($h_listbox) Retrieve the number of items per column in a specified list box. (required: <GuiList.au3>)
  381. ; Author(s):            Gary Frost (custompcs at charter dot net)
  382. ; Note(s):
  383. ;
  384. ;===============================================================================
  385. Func _GUICtrlListGetInfo($h_listbox)
  386.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  387.     If IsHWnd($h_listbox) Then
  388.         Return _SendMessage($h_listbox, $LB_GETLISTBOXINFO)
  389.     Else
  390.         Return GUICtrlSendMsg($h_listbox, $LB_GETLISTBOXINFO, 0, 0)
  391.     EndIf
  392. EndFunc   ;==>_GUICtrlListGetInfo
  393.  
  394. ;===============================================================================
  395. ;
  396. ; Description:            _GUICtrlListGetItemRect
  397. ; Parameter(s):        $h_listbox - controlID
  398. ;                            $i_index - Specifies the zero-based index of the item.
  399. ; Requirement:            Array containing the RECT, first element ($array[0]) contains the number of elements
  400. ;                            If an error occurs, the return value is $LB_ERR.
  401. ; Return Value(s):    The return value is the number of items per column.
  402. ; User CallTip:        _GUICtrlListGetItemRect($h_listbox, $i_index) Retrieve the dimensions of the rectangle that bounds a list box item. (required: <GuiList.au3>)
  403. ; Author(s):            Gary Frost (custompcs at charter dot net)
  404. ; Note(s):                $array[1] - left
  405. ;                            $array[2] - top
  406. ;                            $array[3] - right
  407. ;                            $array[4] - bottom
  408. ;
  409. ;===============================================================================
  410. Func _GUICtrlListGetItemRect($h_listbox, $i_index)
  411.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  412.     #cs
  413.         typedef struct _RECT {
  414.         LONG left;
  415.         LONG top;
  416.         LONG right;
  417.         LONG bottom;
  418.         } RECT, *PRECT;
  419.     #ce
  420.     Local $RECT = "int;int;int;int"
  421.     Local $left = 1, $top = 2, $right = 3, $bottom = 4
  422.     Local $p = DllStructCreate($RECT)
  423.     If @error Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  424.     If IsHWnd($h_listbox) Then
  425.         If _SendMessage($h_listbox, $LB_GETITEMRECT, $i_index, DllStructGetPtr($p), 0, "int", "ptr") == $LB_ERR Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  426.     Else
  427.         If GUICtrlSendMsg($h_listbox, $LB_GETITEMRECT, $i_index, DllStructGetPtr($p)) == $LB_ERR Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  428.     EndIf
  429.     Return StringSplit(DllStructGetData($p, $left) & "," & DllStructGetData($p, $top) & "," & DllStructGetData($p, $right) & "," & DllStructGetData($p, $bottom), ",")
  430. EndFunc   ;==>_GUICtrlListGetItemRect
  431.  
  432. ;===============================================================================
  433. ;
  434. ; Description:            _GUICtrlListGetLocale
  435. ; Parameter(s):        $h_listbox - controlID
  436. ; Requirement:            None
  437. ; Return Value(s):    Returns the current Local of the listbox
  438. ;                             same as @OSLang unless changed
  439. ; User CallTip:        _GUICtrlListGetLocale($h_listbox) current Local of the listbox (required: <GuiList.au3>)
  440. ; Author(s):            CyberSlug
  441. ; Note(s):                "0409" for U.S. English
  442. ;
  443. ;===============================================================================
  444. Func _GUICtrlListGetLocale($h_listbox)
  445.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  446.     If IsHWnd($h_listbox) Then
  447.         Return Hex(_SendMessage($h_listbox, $LB_GETLOCALE), 4)
  448.     Else
  449.         Return Hex(GUICtrlSendMsg($h_listbox, $LB_GETLOCALE, 0, 0), 4)
  450.     EndIf
  451. EndFunc   ;==>_GUICtrlListGetLocale
  452.  
  453. ;===============================================================================
  454. ;
  455. ; Description:            _GUICtrlListGetSelCount
  456. ; Parameter(s):        $h_listbox - controlID
  457. ; Requirement:            multiple-selection list box
  458. ; Return Value(s):    The return value is the count of selected items in the list box.
  459. ;                            If the list box is a single-selection list box, the return value is $LB_ERR.
  460. ; User CallTip:        _GUICtrlListGetSelCount($h_listbox) Get the number of items selected (required: <GuiList.au3>)
  461. ; Author(s):            CyberSlug
  462. ; Note(s):                Retrieve the total number of selected items in a multiple-selection list box.
  463. ;                             Number of selected items (for a control with multi-select style)
  464. ;
  465. ;===============================================================================
  466. Func _GUICtrlListGetSelCount($h_listbox)
  467.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  468.     If IsHWnd($h_listbox) Then
  469.         Return _SendMessage($h_listbox, $LB_GETSELCOUNT)
  470.     Else
  471.         Return GUICtrlSendMsg($h_listbox, $LB_GETSELCOUNT, 0, 0)
  472.     EndIf
  473. EndFunc   ;==>_GUICtrlListGetSelCount
  474.  
  475. ;===============================================================================
  476. ;
  477. ; Description:            _GUICtrlListGetSelItems
  478. ; Parameter(s):        $h_listbox - controlID
  479. ; Requirement:            multi-select style
  480. ; Return Value(s):    Array of selected items indices, first element ($array[0]) contains the number indices returned
  481. ;                            If the list box is a single-selection list box, the return value is $LB_ERR.
  482. ;                            If no items are selected, the return value is $LB_ERR.
  483. ; User CallTip:        _GUICtrlListGetSelItems($h_listbox) Get item indices of selected items (required: <GuiList.au3>)
  484. ; Author(s):            Gary Frost (custompcs at charter dot net)
  485. ; Note(s):
  486. ;
  487. ;===============================================================================
  488. Func _GUICtrlListGetSelItems($h_listbox)
  489.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  490.     Local $num = _GUICtrlListGetSelCount($h_listbox)
  491.     Local $i, $struct, $i_ret
  492.     For $i = 1 To $num
  493.         $struct &= "int;"
  494.     Next
  495.     $struct = StringTrimRight($struct, 1)
  496.     Local $p = DllStructCreate($struct)
  497.     If @error Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  498.     If IsHWnd($h_listbox) Then
  499.         $i_ret = _SendMessage($h_listbox, $LB_GETSELITEMS, $num, DllStructGetPtr($p), 0, "int", "ptr")
  500.     Else
  501.         $i_ret = GUICtrlSendMsg($h_listbox, $LB_GETSELITEMS, $num, DllStructGetPtr($p))
  502.     EndIf
  503.     If ($i_ret == $LB_ERR Or $i_ret == 0) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  504.     Local $array
  505.     For $i = 1 To $num
  506.         $array &= DllStructGetData($p, $i) & ","
  507.     Next
  508.     $array = StringTrimRight($array, 1)
  509.     Local $a_items = StringSplit($array, ",")
  510.     For $i = 1 To $a_items[0]
  511.         $a_items[$i] = Int($a_items[$i])
  512.     Next
  513.     Return $a_items
  514. EndFunc   ;==>_GUICtrlListGetSelItems
  515.  
  516. ;===============================================================================
  517. ;
  518. ; Description:            _GUICtrlListGetSelItemsText
  519. ; Parameter(s):        $h_listbox - controlID
  520. ; Requirement:            multi-select style
  521. ; Return Value(s):    array of selected items text, first element ($array[0]) contains the number items returned
  522. ;                            If the list box is a single-selection list box, the return value is $LB_ERR.
  523. ;                            If no items are selected, the return value is $LB_ERR.
  524. ; User CallTip:        _GUICtrlListGetSelItemsText($h_listbox) Get the text of selected items (required: <GuiList.au3>)
  525. ; Author(s):            Gary Frost (custompcs at charter dot net)
  526. ;                    CyberSlug
  527. ; Note(s):
  528. ;
  529. ;===============================================================================
  530. Func _GUICtrlListGetSelItemsText($h_listbox)
  531.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  532.     Local $i, $i_ret, $a_text
  533.     For $i = 0 To _GUICtrlListCount($h_listbox) - 1
  534.         $i_ret = _GUICtrlListGetSelState($h_listbox, $i)
  535.         If ($i_ret > 0) Then
  536.             If IsArray($a_text) Then
  537.                 ReDim $a_text[UBound($a_text) + 1]
  538.             Else
  539.                 Local $a_text[2]
  540.             EndIf
  541.             $a_text[0] += 1
  542.             $a_text[UBound($a_text) - 1] = _GUICtrlListGetText($h_listbox, $i)
  543.         ElseIf ($i_ret == $LB_ERR) Then
  544.             Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  545.         EndIf
  546.     Next
  547.     Return $a_text
  548. EndFunc   ;==>_GUICtrlListGetSelItemsText
  549.  
  550. ;===============================================================================
  551. ;
  552. ; Description:            _GUICtrlListGetSelState
  553. ; Parameter(s):        $h_listbox - controlID
  554. ;                            $i_index - Specifies the zero-based index of the item
  555. ; Requirement:            None
  556. ; Return Value(s):    If an item is selected, the return value is greater than zero
  557. ;                             otherwise, it is zero. If an error occurs, the return value is $LB_ERR.
  558. ; User CallTip:        _GUICtrlListGetSelState($h_listbox, $i_index) Get the selection state of item (required: <GuiList.au3>)
  559. ; Author(s):            CyberSlug
  560. ; Note(s):                None
  561. ;
  562. ;===============================================================================
  563. Func _GUICtrlListGetSelState($h_listbox, $i_index)
  564.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  565.     If IsHWnd($h_listbox) Then
  566.         Return _SendMessage($h_listbox, $LB_GETSEL, $i_index)
  567.     Else
  568.         Return GUICtrlSendMsg($h_listbox, $LB_GETSEL, $i_index, 0)
  569.     EndIf
  570. EndFunc   ;==>_GUICtrlListGetSelState
  571.  
  572. ;===============================================================================
  573. ;
  574. ; Description:            _GUICtrlListGetText
  575. ; Parameter(s):        $h_listbox - controlID
  576. ;                            $i_index - Specifies the zero-based index of the string to retrieve
  577. ; Requirement:            None
  578. ; Return Value(s):    The return value is the item string.
  579. ;                            If $i_index does not specify a valid index, the return value is $LB_ERR.
  580. ; User CallTip:        _GUICtrlListGetText($h_listbox, $i_index) Returns the item (string) at the specified index (required: <GuiList.au3>)
  581. ; Author(s):            CyberSlug
  582. ; Note(s):                None
  583. ;
  584. ;===============================================================================
  585. Func _GUICtrlListGetText($h_listbox, $i_index)
  586.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  587.     Local $v_ret
  588.     Local $struct = DllStructCreate("char[4096]")
  589.     If @error Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  590.  
  591.     If Not IsHWnd($h_listbox) Then $h_listbox = GUICtrlGetHandle($h_listbox)
  592.     $v_ret = DllCall("user32.dll", "int", "SendMessageA", "hwnd", $h_listbox, "int", $LB_GETTEXT, "int", $i_index, "ptr", DllStructGetPtr($struct))
  593.     If $v_ret[0] == $LB_ERR Or @error Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  594.     Return DllStructGetData($struct, 1)
  595. EndFunc   ;==>_GUICtrlListGetText
  596.  
  597. ;===============================================================================
  598. ;
  599. ; Description:            _GUICtrlListGetTextLen
  600. ; Parameter(s):        $h_listbox - controlID
  601. ;                            $i_index - Zero-based index of item
  602. ; Requirement:            None
  603. ; Return Value(s):    The return value is the length of the string
  604. ;                            If the wParam parameter does not specify a valid index, the return value is $LB_ERR
  605. ; User CallTip:        _GUICtrlListGetTextLen($h_listbox, $i_index) alternative to StringLen (required: <GuiList.au3>)
  606. ; Author(s):            CyberSlug
  607. ; Note(s):                None
  608. ;
  609. ;===============================================================================
  610. Func _GUICtrlListGetTextLen($h_listbox, $i_index)
  611.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  612.     If IsHWnd($h_listbox) Then
  613.         Return _SendMessage($h_listbox, $LB_GETTEXTLEN, $i_index)
  614.     Else
  615.         Return GUICtrlSendMsg($h_listbox, $LB_GETTEXTLEN, $i_index, 0)
  616.     EndIf
  617. EndFunc   ;==>_GUICtrlListGetTextLen
  618.  
  619. ;===============================================================================
  620. ;
  621. ; Description:            _GUICtrlListGetTopIndex
  622. ; Parameter(s):        $h_listbox - controlID
  623. ; Requirement:            None
  624. ; Return Value(s):    The return value is the index of the first visible item in the list box.
  625. ;                            If the list is empty then $LB_ERR is returned.
  626. ; User CallTip:        _GUICtrlListGetTopIndex($h_listbox) retrieve the index of the first visible item in a list (required: <GuiList.au3>)
  627. ; Author(s):            Gary Frost (custompcs at charter dot net)
  628. ;                    CyberSlug
  629. ; Note(s):                Initially the item with index 0 is at the top of the list box, but if
  630. ;                             the list box contents have been scrolled another item may be at the top.
  631. ;                             Returns index of the first visible item in the list box
  632. ;                             useful since contents for a long list will scroll
  633. ;
  634. ;===============================================================================
  635. Func _GUICtrlListGetTopIndex($h_listbox)
  636.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  637.     If (Not _GUICtrlListCount($h_listbox)) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  638.     If IsHWnd($h_listbox) Then
  639.         Return _SendMessage($h_listbox, $LB_GETTOPINDEX)
  640.     Else
  641.         Return GUICtrlSendMsg($h_listbox, $LB_GETTOPINDEX, 0, 0)
  642.     EndIf
  643. EndFunc   ;==>_GUICtrlListGetTopIndex
  644.  
  645. ;===============================================================================
  646. ;
  647. ; Description:            _GUICtrlListInsertItem
  648. ; Parameter(s):        $h_listbox - controlID
  649. ;                            $s_text - String to insert
  650. ;                            $i_index - Optional: index to insert at
  651. ; Requirement:            None
  652. ; Return Value(s):    The return value is the index of the position at which the string was inserted.
  653. ;                            If an error occurs, the return value is $LB_ERR. If there is insufficient space
  654. ;                            to store the new string, the return value is $LB_ERRSPACE.
  655. ; User CallTip:        _GUICtrlListInsertItem($h_listbox, $s_text[, $i_index=-1]) insert a string into the list (required: <GuiList.au3>)
  656. ; Author(s):            Gary Frost (custompcs at charter dot net)
  657. ; Note(s):                If this parameter is û1, the string is added to the end of the list.
  658. ;                             Unlike the _GUICtrlListAddItem, this function does not cause a list
  659. ;                             with the LBS_SORT style to be sorted.
  660. ;
  661. ;===============================================================================
  662. Func _GUICtrlListInsertItem($h_listbox, $s_text, $i_index = -1)
  663.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  664.     If IsHWnd($h_listbox) Then
  665.         Local $struct_String = DllStructCreate("char[" & StringLen($s_text) + 1 & "]")
  666.         Local $sBuffer_pointer = DllStructGetPtr($struct_String)
  667.         DllStructSetData($struct_String, 1, $s_text)
  668.         Local $rMemMap
  669.         _MemInit ($h_listbox, StringLen($s_text) + 1, $rMemMap)
  670.         If @error Then
  671.             _MemFree ($rMemMap)
  672.             Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  673.         EndIf
  674.         _MemWrite ($rMemMap, $sBuffer_pointer)
  675.         If @error Then
  676.             _MemFree ($rMemMap)
  677.             Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  678.         EndIf
  679.         Local $iResult = _SendMessage($h_listbox, $LB_INSERTSTRING, $i_index, $sBuffer_pointer)
  680.         If @error Then
  681.             _MemFree ($rMemMap)
  682.             Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  683.         EndIf
  684.         _MemFree ($rMemMap)
  685.         If @error Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  686.         Return $iResult
  687.     Else
  688.         Return GUICtrlSendMsg($h_listbox, $LB_INSERTSTRING, $i_index, String($s_text))
  689.     EndIf
  690. EndFunc   ;==>_GUICtrlListInsertItem
  691.  
  692. ;===============================================================================
  693. ;
  694. ; Description:            _GUICtrlListReplaceString
  695. ; Parameter(s):        $h_listbox - controlID
  696. ;                            $i_index - Zero-based index of the item to replace
  697. ;                            $s_newString - String to replace old string
  698. ; Requirement:            None
  699. ; Return Value(s):    If an error occurs, the return value is $LB_ERR
  700. ; User CallTip:        _GUICtrlListReplaceString($h_listbox, $i_index, $s_newString) Replaces the text of an item at index (required: <GuiList.au3>)
  701. ; Author(s):            Gary Frost (custompcs at charter dot net)
  702. ;                    CyberSlug
  703. ; Note(s):                None
  704. ;
  705. ;===============================================================================
  706. Func _GUICtrlListReplaceString($h_listbox, $i_index, $s_newString)
  707.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  708.     If (_GUICtrlListDeleteItem($h_listbox, $i_index) == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  709.     If (_GUICtrlListInsertItem($h_listbox, $s_newString, $i_index) == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  710. EndFunc   ;==>_GUICtrlListReplaceString
  711.  
  712. ;===============================================================================
  713. ;
  714. ; Description:            _GUICtrlListSelectIndex
  715. ; Parameter(s):        $h_listbox - controlID
  716. ;                            $i_index - Specifies the zero-based index of the list box item
  717. ; Requirement:
  718. ; Return Value(s):    If an error occurs, the return value is $LB_ERR.
  719. ;                            If the $i_index parameter is û1, the return value is $LB_ERR even though no error occurred.
  720. ; User CallTip:        _GUICtrlListSelectIndex($h_listbox, $i_index) Select a string and scroll it into view, if necessary (required: <GuiList.au3>)
  721. ; Author(s):            Sokko, Documented and Added To UDFs (Gary Frost (custompcs at charter dot net))
  722. ; Note(s):                Use this message only with single-selection list boxes.
  723. ;                            You cannot use it to set or remove a selection in a multiple-selection list box.
  724. ;
  725. ;===============================================================================
  726. Func _GUICtrlListSelectIndex($h_listbox, $i_index)
  727.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  728.     If IsHWnd($h_listbox) Then
  729.         Return _SendMessage($h_listbox, $LB_SETCURSEL, $i_index)
  730.     Else
  731.         Return GUICtrlSendMsg($h_listbox, $LB_SETCURSEL, $i_index, 0)
  732.     EndIf
  733. EndFunc   ;==>_GUICtrlListSelectIndex
  734.  
  735. ;===============================================================================
  736. ;
  737. ; Description:            _GUICtrlListSelectedIndex
  738. ; Parameter(s):        $h_listbox - controlID
  739. ; Requirement:            None
  740. ; Return Value(s):    In a single-selection list box, the return value is the zero-based
  741. ;                            index of the currently selected item. If there is no selection,
  742. ;                            the return value is $LB_ERR
  743. ; User CallTip:        _GUICtrlListSelectedIndex($h_listbox) return the index of selected item (required: <GuiList.au3>)
  744. ; Author(s):            Gary Frost (custompcs at charter dot net)
  745. ; Note(s):                Do not use this with a multiple-selection list box.
  746. ;
  747. ;===============================================================================
  748. Func _GUICtrlListSelectedIndex($h_listbox)
  749.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  750.     If IsHWnd($h_listbox) Then
  751.         Return _SendMessage($h_listbox, $LB_GETCURSEL)
  752.     Else
  753.         Return GUICtrlSendMsg($h_listbox, $LB_GETCURSEL, 0, 0)
  754.     EndIf
  755. EndFunc   ;==>_GUICtrlListSelectedIndex
  756.  
  757. ;===============================================================================
  758. ;
  759. ; Description:            _GUICtrlListSelectString
  760. ; Parameter(s):        $h_listbox - controlID
  761. ;                            $s_text - String to select
  762. ;                            $i_index - Optional: Zero-based index of the item before the first item to be searched
  763. ; Requirement:            None
  764. ; Return Value(s):    If the search is successful, the return value is the index of the selected item.
  765. ;                            If the search is unsuccessful, the return value is $LB_ERR and the current selection is not changed.
  766. ; User CallTip:        _GUICtrlListSelectString($h_listbox, $s_text[, $i_index=-1]) select item using search string (required: <GuiList.au3>)
  767. ; Author(s):            Gary Frost (custompcs at charter dot net)
  768. ; Note(s):                If $i_index is û1, the entire list box is searched from the beginning
  769. ;
  770. ;===============================================================================
  771. Func _GUICtrlListSelectString($h_listbox, $s_search, $i_index = -1)
  772.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  773.     If IsHWnd($h_listbox) Then
  774.         Return _SendMessage($h_listbox, $LB_SELECTSTRING, $i_index, $s_search, 0, "int", "str")
  775.     Else
  776.         Return GUICtrlSendMsg($h_listbox, $LB_SELECTSTRING, $i_index, String($s_search))
  777.     EndIf
  778. EndFunc   ;==>_GUICtrlListSelectString
  779.  
  780. ;===============================================================================
  781. ;
  782. ; Description:            _GUICtrlListSelItemRange
  783. ; Parameter(s):        $h_listbox - controlID
  784. ;                            $i_flag - Set/Remove select
  785. ;                            $i_start - Zero-based index of the first item to select
  786. ;                            $i_stop - Zero-based index of the last item to select
  787. ; Requirement:            multi-select style
  788. ; Return Value(s):    If an error occurs, the return value is $LB_ERR
  789. ; User CallTip:        _GUICtrlListSelItemRange($h_listbox, $i_flag, $i_start, $i_stop) Select range by index in a multiple-selection list box (required: <GuiList.au3>)
  790. ; Author(s):            Gary Frost (custompcs at charter dot net)
  791. ;                    CyberSlug
  792. ; Note(s):                DOES NOT WORK WITH SINGLE-SELECTION LIST BOXES
  793. ;                             Select items from $i_start to $stop indices (inclusive)
  794. ;                            Can select a range only within the first 65,536 items
  795. ;                             $i_flag == 1 selects
  796. ;                             $i_flag == 0 removes select
  797. ;
  798. ;===============================================================================
  799. Func _GUICtrlListSelItemRange($h_listbox, $i_flag, $i_start, $i_stop)
  800.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  801.     If IsHWnd($h_listbox) Then
  802.         Return _SendMessage($h_listbox, $LB_SELITEMRANGE, $i_flag, $i_stop * 65536 + $i_start)
  803.     Else
  804.         Return GUICtrlSendMsg($h_listbox, $LB_SELITEMRANGE, $i_flag, $i_stop * 65536 + $i_start)
  805.     EndIf
  806. EndFunc   ;==>_GUICtrlListSelItemRange
  807.  
  808. ;===============================================================================
  809. ;
  810. ; Description:            _GUICtrlListSelItemRangeEx
  811. ; Parameter(s):        $h_listbox - controlID
  812. ;                            $i_start - Zero-based index of the first item to select
  813. ;                            $i_stop - Zero-based index of the last item to select
  814. ; Requirement:            multi-select style
  815. ; Return Value(s):    If an error occurs, the return value is $LB_ERR
  816. ; User CallTip:        _GUICtrlListSelItemRangeEx($h_listbox, $i_start, $i_stop) Selects items from $i_start to $i_stop (required: <GuiList.au3>)
  817. ; Author(s):            CyberSlug
  818. ; Note(s):                DOES NOT WORK WITH SINGLE-SELECTION LIST BOXES
  819. ;                          If $i_start > $i_stop Then items are un-selected
  820. ;
  821. ;===============================================================================
  822. Func _GUICtrlListSelItemRangeEx($h_listbox, $i_start, $i_stop)
  823.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  824.     If IsHWnd($h_listbox) Then
  825.         Return _SendMessage($h_listbox, $LB_SELITEMRANGEEX, $i_start, $i_stop)
  826.     Else
  827.         Return GUICtrlSendMsg($h_listbox, $LB_SELITEMRANGEEX, $i_start, $i_stop)
  828.     EndIf
  829. EndFunc   ;==>_GUICtrlListSelItemRangeEx
  830.  
  831. ;===============================================================================
  832. ;
  833. ; Description:            _GUICtrlListSetAnchorIndex
  834. ; Parameter(s):        $h_listbox - controlID
  835. ;                            $i_index - Specifies the index of the new anchor item.
  836. ; Requirement:            multi-select style
  837. ; Return Value(s):    If the message succeeds, the return value is zero.
  838. ;                            If the message fails, the return value is $LB_ERR.
  839. ; User CallTip:        _GUICtrlListSetAnchorIndex($h_listbox, $i_index) Set the Anchor Idex (required: <GuiList.au3>)
  840. ; Author(s):            Gary Frost (custompcs at charter dot net)
  841. ; Note(s):                DOES NOT WORK WITH SINGLE-SELECTION LIST BOXES
  842. ;
  843. ;===============================================================================
  844. Func _GUICtrlListSetAnchorIndex($h_listbox, $i_index)
  845.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  846.     If IsHWnd($h_listbox) Then
  847.         Return _SendMessage($h_listbox, $LB_SETANCHORINDEX, $i_index)
  848.     Else
  849.         Return GUICtrlSendMsg($h_listbox, $LB_SETANCHORINDEX, $i_index, 0)
  850.     EndIf
  851. EndFunc   ;==>_GUICtrlListSetAnchorIndex
  852.  
  853. ;===============================================================================
  854. ;
  855. ; Description:            _GUICtrlListGetCaretIndex
  856. ; Parameter(s):        $h_listbox - controlID
  857. ;                            $i_index - Specifies the zero-based index of the list box item that is to receive the focus rectangle.
  858. ;                            $i_bool - Optional: If this value is FALSE, the item is scrolled until it is fully visible; if it is TRUE, the item is scrolled until it is at least partially visible.
  859. ; Requirement:            multi-select style
  860. ; Return Value(s):    The return value is the zero-based index of the selected list box item.
  861. ;                            If nothing is selected $LB_ERR can be returned.
  862. ; User CallTip:        _GUICtrlListSetCaretIndex($h_listbox, $i_index[, $i_bool=1]) Set the focus rectangle to the item at the specified index (required: <GuiList.au3>)
  863. ; Author(s):            Gary Frost (custompcs at charter dot net)
  864. ; Note(s):                DOES NOT WORK WITH SINGLE-SELECTION LIST BOXES
  865. ;
  866. ;===============================================================================
  867. Func _GUICtrlListSetCaretIndex($h_listbox, $i_index, $i_bool = 1)
  868.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  869.     If IsHWnd($h_listbox) Then
  870.         Return _SendMessage($h_listbox, $LB_SETCARETINDEX, $i_index, $i_bool)
  871.     Else
  872.         Return GUICtrlSendMsg($h_listbox, $LB_SETCARETINDEX, $i_index, $i_bool)
  873.     EndIf
  874. EndFunc   ;==>_GUICtrlListSetCaretIndex
  875.  
  876. ;===============================================================================
  877. ;
  878. ; Description:            _GUICtrlListSetHorizontalExtent
  879. ; Parameter(s):        $h_listbox - controlID
  880. ;                            $i_pixels - Specifies the number of pixels by which the list box can be scrolled.
  881. ; Requirement:            None.
  882. ; Return Value(s):    None.
  883. ; User CallTip:        _GUICtrlListSetHorizontalExtent($h_listbox, $i_num) Set the width, in pixels, by which a list box can be scrolled horizontally (required: <GuiList.au3>)
  884. ; Author(s):            Gary Frost (custompcs at charter dot net)
  885. ; Note(s):                To respond to the $LB_SETHORIZONTALEXTENT message,
  886. ;                            the list box must have been defined with the $WS_HSCROLL style.
  887. ;
  888. ;===============================================================================
  889. Func _GUICtrlListSetHorizontalExtent($h_listbox, $i_pixels)
  890.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  891.     If IsHWnd($h_listbox) Then
  892.         _SendMessage($h_listbox, $LB_SETHORIZONTALEXTENT, $i_pixels)
  893.     Else
  894.         GUICtrlSendMsg($h_listbox, $LB_SETHORIZONTALEXTENT, $i_pixels, 0)
  895.     EndIf
  896. EndFunc   ;==>_GUICtrlListSetHorizontalExtent
  897.  
  898. ;===============================================================================
  899. ;
  900. ; Description:            _GUICtrlListSetLocale
  901. ; Parameter(s):        $h_listbox - controlID
  902. ;                            $s_locale - locale
  903. ; Requirement:            None
  904. ; Return Value(s):    Returns previous locale or $LB_ERR
  905. ; User CallTip:        _GUICtrlListSetLocale($h_listbox, $s_locale) Set the locale (required: <GuiList.au3>)
  906. ; Author(s):            CyberSlug
  907. ; Note(s):                "0409" for U.S. English
  908. ;                            see @OSLang for string values
  909. ;
  910. ;===============================================================================
  911. Func _GUICtrlListSetLocale($h_listbox, $s_locale)
  912.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  913.     If IsHWnd($h_listbox) Then
  914.         Return Hex(_SendMessage($h_listbox, $LB_SETLOCALE, Dec($s_locale)), 4)
  915.     Else
  916.         Return Hex(GUICtrlSendMsg($h_listbox, $LB_SETLOCALE, Dec($s_locale), 0), 4)
  917.     EndIf
  918. EndFunc   ;==>_GUICtrlListSetLocale
  919.  
  920. ;===============================================================================
  921. ;
  922. ; Description:            _GUICtrlListSetSel
  923. ; Parameter(s):        $h_listbox - controlID
  924. ;                            $i_flag - Optional: Select/UnSelect
  925. ;                            $i_index - Optional: Specifies the zero-based index of the item
  926. ; Requirement:            multi-select style
  927. ; Return Value(s):    If an error occurs, the return value is $LB_ERR
  928. ; User CallTip:        _GUICtrlListSetSel($h_listbox [, $i_flag] , $i_index]]) Select string(s) in a multiple-selection list box (required: <GuiList.au3>)
  929. ; Author(s):            Gary Frost (custompcs at charter dot net)
  930. ;                    CyberSlug
  931. ; Note(s):                DOES NOT WORK WITH SINGLE-SELECTION LIST BOXES
  932. ;                             $i_flag == 0 means unselect
  933. ;                             $i_flag == 1 means select
  934. ;                            $i_flag == -1 means toggle select/unselect of item
  935. ;                             An $i_index of -1 means to toggle select/unselect of all items (ignores the $i_flag).
  936. ;
  937. ;===============================================================================
  938. Func _GUICtrlListSetSel($h_listbox, $i_flag = -1, $i_index = -1)
  939.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  940.     Local $i_ret
  941.     If IsHWnd($h_listbox) Then
  942.         If $i_index == -1 Then ; toggle all
  943.             For $i_index = 0 To _GUICtrlListCount($h_listbox) - 1
  944.                 $i_ret = _GUICtrlListGetSelState($h_listbox, $i_index)
  945.                 If ($i_ret == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  946.                 If ($i_ret > 0) Then ;If Selected Then
  947.                     $i_ret = _SendMessage($h_listbox, $LB_SETSEL, 0, $i_index)
  948.                 Else
  949.                     $i_ret = _SendMessage($h_listbox, $LB_SETSEL, 1, $i_index)
  950.                 EndIf
  951.                 If ($i_ret == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  952.             Next
  953.         ElseIf $i_flag == -1 Then ; toggle state of index
  954.             If _GUICtrlListGetSelState($h_listbox, $i_index) Then ;If Selected Then
  955.                 Return _SendMessage($h_listbox, $LB_SETSEL, 0, $i_index)
  956.             Else
  957.                 Return _SendMessage($h_listbox, $LB_SETSEL, 1, $i_index)
  958.             EndIf
  959.         Else
  960.             Return _SendMessage($h_listbox, $LB_SETSEL, $i_flag, $i_index)
  961.         EndIf
  962.     Else
  963.         If $i_index == -1 Then ; toggle all
  964.             For $i_index = 0 To _GUICtrlListCount($h_listbox) - 1
  965.                 $i_ret = _GUICtrlListGetSelState($h_listbox, $i_index)
  966.                 If ($i_ret == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  967.                 If ($i_ret > 0) Then ;If Selected Then
  968.                     $i_ret = GUICtrlSendMsg($h_listbox, $LB_SETSEL, 0, $i_index)
  969.                 Else
  970.                     $i_ret = GUICtrlSendMsg($h_listbox, $LB_SETSEL, 1, $i_index)
  971.                 EndIf
  972.                 If ($i_ret == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  973.             Next
  974.         ElseIf $i_flag == -1 Then ; toggle state of index
  975.             If _GUICtrlListGetSelState($h_listbox, $i_index) Then ;If Selected Then
  976.                 Return GUICtrlSendMsg($h_listbox, $LB_SETSEL, 0, $i_index)
  977.             Else
  978.                 Return GUICtrlSendMsg($h_listbox, $LB_SETSEL, 1, $i_index)
  979.             EndIf
  980.         Else
  981.             Return GUICtrlSendMsg($h_listbox, $LB_SETSEL, $i_flag, $i_index)
  982.         EndIf
  983.     EndIf
  984. EndFunc   ;==>_GUICtrlListSetSel
  985.  
  986. ;===============================================================================
  987. ;
  988. ; Description:            _GUICtrlListSetTopIndex
  989. ; Parameter(s):        $h_listbox - controlID
  990. ;                            $i_index - Specifies the zero-based index of the item
  991. ; Requirement:            None
  992. ; Return Value(s):    If an error occurs, the return value is $LB_ERR
  993. ; User CallTip:        _GUICtrlListSetTopIndex($h_listbox, $i_index) ensure that a particular item in a list box is visible (required: <GuiList.au3>)
  994. ; Author(s):            CyberSlug
  995. ; Note(s):                None
  996. ;
  997. ;===============================================================================
  998. Func _GUICtrlListSetTopIndex($h_listbox, $i_index)
  999.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  1000.     If IsHWnd($h_listbox) Then
  1001.         Return _SendMessage($h_listbox, $LB_SETTOPINDEX, $i_index)
  1002.     Else
  1003.         Return GUICtrlSendMsg($h_listbox, $LB_SETTOPINDEX, $i_index, 0)
  1004.     EndIf
  1005. EndFunc   ;==>_GUICtrlListSetTopIndex
  1006.  
  1007. ;===============================================================================
  1008. ;
  1009. ; Description:            _GUICtrlListSort
  1010. ; Parameter(s):        $h_listbox - controlID
  1011. ; Requirement:            None
  1012. ; Return Value(s):    If an error occurs, the return value is $LB_ERR
  1013. ; User CallTip:        _GUICtrlListSort($h_listbox) Re-sorts list box if it has the LBS_SORT style (required: <GuiList.au3>)
  1014. ; Author(s):            Gary Frost (custompcs at charter dot net)
  1015. ;                    CyberSlug
  1016. ; Note(s):                Re-sorts list box if it has the LBS_SORT style
  1017. ;                          Might be useful if you use InsertString
  1018. ;
  1019. ;===============================================================================
  1020. Func _GUICtrlListSort($h_listbox)
  1021.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  1022.     Local $bak = _GUICtrlListGetText($h_listbox, 0)
  1023.     If ($bak == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  1024.     If (_GUICtrlListDeleteItem($h_listbox, 0) == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  1025.     Return _GUICtrlListAddItem($h_listbox, $bak)
  1026. EndFunc   ;==>_GUICtrlListSort
  1027.  
  1028. ;===============================================================================
  1029. ;
  1030. ; Description:            _GUICtrlListSwapString
  1031. ; Parameter(s):        $h_listbox - controlID
  1032. ;                            $i_indexA - Zero-based index item to swap
  1033. ;                            $i_indexB - Zero-based index item to swap
  1034. ; Requirement:            None
  1035. ; Return Value(s):    If an error occurs, the return value is $LB_ERR
  1036. ; User CallTip:        _GUICtrlListSwapString($h_listbox, $i_indexA, $i_indexB) Swaps the text of two items at the specified indices (required: <GuiList.au3>)
  1037. ; Author(s):            Gary Frost (custompcs at charter dot net)
  1038. ;                    CyberSlug
  1039. ; Note(s):                None
  1040. ;
  1041. ;===============================================================================
  1042. Func _GUICtrlListSwapString($h_listbox, $i_indexA, $i_indexB)
  1043.     If Not _IsClassName ($h_listbox, "ListBox") Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  1044.     Local $itemA = _GUICtrlListGetText($h_listbox, $i_indexA)
  1045.     Local $itemB = _GUICtrlListGetText($h_listbox, $i_indexB)
  1046.     If ($itemA == $LB_ERR Or $itemB == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  1047.     If (_GUICtrlListDeleteItem($h_listbox, $i_indexA) == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  1048.     If (_GUICtrlListInsertItem($h_listbox, $itemB, $i_indexA) == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  1049.  
  1050.     If (_GUICtrlListDeleteItem($h_listbox, $i_indexB) == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  1051.     If (_GUICtrlListInsertItem($h_listbox, $itemA, $i_indexB) == $LB_ERR) Then Return SetError($LB_ERR, $LB_ERR, $LB_ERR)
  1052. EndFunc   ;==>_GUICtrlListSwapString